﻿// Inner Fire 游戏引擎库
// UI - 组件控件
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 用于UI的组件-基础类型
// 所有的UI控件都需要继承此类
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-01-07

#pragma once

#include <functional>
#include <ui/manager/ui_event.h>
#include <ui/ui_base.h>

namespace ifire::ui {

class UIComponent;

// 定义按钮的点击状态枚举
enum class ClickEventState {
  DOWN, // 当玩家按下按钮
  UP,   // 当玩家抬起按钮
};

using HoverCallback = std::function<void(UIComponent*, bool)>;
using PushedCallback = std::function<void(UIComponent*, bool)>;
using ClickCallback = std::function<void(UIComponent*)>;

class UIComponent {
public:
  UIComponent(ikit::sstr name);
  UIComponent(const UIComponent& lhs) = delete;
  UIComponent& operator=(const UIComponent& lhs) = delete;
  ~UIComponent() = default;

  const ikit::sstr Name() const { return name_; }
  void SetHover(bool state);
  void SetPushed(bool state);
  bool IsHover() const { return is_hover_; }
  bool IsPushed() const { return is_pushed_; }
  

  void AddHoverChangedListener(HoverCallback callback);
  void AddClickListener(ClickCallback callback);
  void AddPushedListener(PushedCallback callback);

  // 使用默认的Hover状态
  void SetDefaultHoverAction();
  void SetDefaultPushedAction();

  // 执行点击的事件
  void PerformClick();

  virtual void SetVisible(bool state);
  virtual void SetScale(XMFLOAT2 scale);
  virtual void SetRefresh();
private:
  bool visible_;
  ikit::sstr name_;
  bool is_hover_;
  bool is_pushed_;
  HoverCallback hover_callback_;
  ClickCallback click_callback_;
  PushedCallback pushed_callback_;
};

} // namespace ifire::ui